home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / getcpu.lha / ...cd / The_Archives / programmers / getcpu.s
Encoding:
Text File  |  1980-02-06  |  3.0 KB  |  75 lines

  1.  
  2. *******************************************************************************
  3. * GetCPU
  4. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  5. *    This routine will allow us to determine the type of CPU installed in
  6. * the host. Trying any 68010/020/030 instructions will cause either an Illegal 
  7. * Instruction or a 1111 Opcode error exception if the respective parts aren't
  8. * present. e.g if the CPU is a 68000, so we set up trap to cater for this.
  9. *
  10. * INPUTS ;    None.
  11. * OUTPUTS;    d0=AFB Bits... se below for there meanings...
  12. *******************************************************************************
  13. AFB_68010    =    0            ;bit to set if MC68010
  14. AFB_68020    =    1            ;bit to set if MC68020
  15. AFB_68030    =    2            ;bit to set if MC68030
  16. AFB_68040    =    3            ;bit to set if MC68040
  17.  
  18. AFB_68881    =    4            ;bit to set if a maths 68881
  19. AFB_68882    =    5            ;bit to set if a maths 68882
  20.  
  21. ;
  22. CACR_ON        =    1            ;instruction cache on
  23. CACR_OFF    =    0            ;instruction cache off
  24.  
  25. GetCPU:        movem.l    a2/a3,-(sp)        ;preserve regs
  26.         move.l    $10.w,a0        ;'Illegal instruction' vector
  27.         move.l    $2c.w,a2        ;'1111 Opcode' error vector
  28.  
  29.         lea    CPUHandler(pc),a1    ;set up a new temp handler
  30.         move.l    a1,$10.w        ;Temp 'Illegal Instruction'
  31.         move.l    a1,$2c.w        ;Temp '1111 Opcode'
  32.         move.l    sp,a1            ;save the stack pointer
  33.  
  34. ;    Initialize the flags to zero (D0), and point to address zero (D1).
  35. ; Then we try to set the 68010 Vector Base Register, which determines where the
  36. ; exception vector table is.  In the 68000, this is hardwired at zero.  If the
  37. ; 68010 is present, we set it to zero. If the VBR was not at 0 then a0 and a1
  38. ; will contain garbage... they will not contain the 'Illegal Instruction' or
  39. ; 1111 Opcode' vector addresses.
  40.  
  41.         moveq    #0,d0            ;clear d1 (VBR_ADDRESS)
  42.         movec    D0,VBR            ;Vector Base Register to 0.
  43.  
  44. ;    If we're still here, the CPU is at least a 68010.  We thus set
  45. ; the AFB_68010 flag.  Then we try to access a 68020-specific feature, namely,
  46. ; we try to enable its INSTRUCTION CACHE.
  47.  
  48.         moveq    #0,d0            ;clear d0 (AFB_FLAGS)
  49.         bset    #AFB_68010,d0        ;Set AFB_68010 flag.
  50.         moveq    #CACR_ON,d1        ;try to turn it on
  51.         movec    d1,CACR            ;Try enabling the 68020 cache.
  52.  
  53. ;    If we're still here, we have a 68020, and so we set the AFB_68020
  54. ; flag.  Then we see if we also have a 68881 FPCP, by trying to access one of
  55. ; its registers. Note; This will not cause an exception if no FPP is present.
  56.  
  57.         bset    #AFB_68020,d0        ;Set AFB_68020 flag.
  58.  
  59. ;        fmove.l    FPCR,d1            ; Try reading a 68881 register.
  60. ;        tst.l    d1            ; Did it work?
  61. ;        bne.s    CPUHandler
  62. ;        bset    #AFB_68881,d0        ; If so,set the AFB_68881 flag.
  63. ;
  64. ; We continue here either from above, or, on plain Amigas, by an error 
  65. ; exception from one of the foreign instructions above. d0 contains all the 
  66. ; flags which have been set along the way. We restore the two changed entries 
  67. ; in the EVT and the stack pointer, then exit.
  68.  
  69. CPUHandler:    move.l    a1,sp            ; Restore stack pointer.
  70.         move.l    a0,$10.w        ; Restore 'Illegal Instruction'
  71.         move.l    a2,$2c.w        ; Restore '1111 OpCode'
  72.         movem.l    (sp)+,a2/a3        ; restore trashed registers
  73.         rts
  74.  
  75.